package com.example.jf.jfapp.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.jf.jfapp.R;
import com.example.jf.jfapp.fragment.Shouye.zixunFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by jf on 2017/7/27.
 */

public class ShouyeFragment extends Fragment {
    @BindView(R.id.tl_souye)
    TabLayout tlSouye;
    @BindView(R.id.vp_souye)
    ViewPager vpSouye;
    Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_souye, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }
    ArrayList<Fragment> fragments = new ArrayList<>();
    String[] titles = new String[]{"机锋资讯","开班信息","行业杂烩"};

    private void initView() {

        fragments.add(new zixunFragment());
        fragments.add(new zixunFragment());
        fragments.add(new zixunFragment());
        vpSouye.setAdapter(new FocusAdapter(getChildFragmentManager()));
        tlSouye.setupWithViewPager(vpSouye);
        vpSouye.setOffscreenPageLimit(fragments.size());
    }

    class FocusAdapter extends FragmentStatePagerAdapter {
        public FocusAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
//            return "我是标题";
        }

        @Override
        public android.support.v4.app.Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
